﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.Office.Interop.Excel;

namespace ObjectModel.Excel
{
    /// <summary>
    /// Decorator class which holds a reference to a live range object which is fetched
    /// from serializable info when an instance of this class is created. Assumes that
    /// the underlying range object will always be available for the duration of this object's life.
    /// </summary>
    public class CachedRange : ISerializableRange
    {
    	public OfflineRangeOld OfflineRange; // Must be kept as a field so it's instantiated before constructor is called.


        public CachedRange() // Parameterless constructor required for serialization.
        {
            Initialize();
        }

        public CachedRange(OfflineRangeOld offlineRange)
        {
            OfflineRange = offlineRange;

            Initialize();
        }

        void Initialize()
        {
            Range = OfflineRange.Range;
        }

        [XmlIgnore]
        public Range Range { get; set; }

        public string Address
        {
            get { return OfflineRange.Address; }
            set { OfflineRange.Address = value; }
        }

        public string WorksheetName
        {
            get { return OfflineRange.WorksheetName; }
            set { OfflineRange.WorksheetName = value; }
        }

        public string WorkbookName
        {
            get { return OfflineRange.WorkbookName; }
            set { OfflineRange.WorkbookName = value; }
        }

        public string WorkbookFullName
        {
            get { return OfflineRange.WorkbookFullName; }
            set { OfflineRange.WorkbookFullName = value; }
        }
    }
}
